package com.lh.java.mongodb;

import java.net.UnknownHostException;

import com.lh.log.log4j.StaticLogOptimize;
import com.mongodb.DB;
import com.mongodb.Mongo;

public class MongoDbDateSorce {	
	private MongoDbDateSorce(){}
//	private static MongoDbDateSorce mongodbS = new MongoDbDateSorce();
	private static DB db ;
	private static Mongo mongo ;
	static{		
		try {
			mongo = new Mongo("127.0.0.1",27017);
			db  = mongo.getDB("mydb");
			StaticLogOptimize.debug("初始化MongoDB连接成功");				
		} catch (UnknownHostException e) {
			StaticLogOptimize.debug("初始化MongoDB连接失败"+e.toString());				
		}		
		
//		boolean auth = db.authenticate(myUserName, myPassword);
	} 
	
	public static  DB getDbInstance() {
		return db;
	}
	
	public static void close() {
		mongo.close();
	}
	
	
	
	public static void main(String[] args) {
		MongoDbDateSorce.getDbInstance();
	}
	
	

}
